﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using QLHocSinh.DAO;
using QLHocSinh.DTO;
using QLHocSinh.BUS;

namespace QLHocSinh.DAO
{
    public class LopHocDAO
    {
        public static DataTable SelectAll()
        {
            string Sql = "SELECT * FROM LOPHOC";
            return Config.AccessHelper.ExecuteQuery(Sql);
        }
        public static bool Insert(LopHocDTO lh)
        {
            try
            {
                string Sql = "INSERT INTO LOPHOC(TenLop, SiSo, MaKhoi) VALUES('" + lh.TenLop + "'," + lh.SiSo + ",'" + lh.MaKhoi + "')";
                Config.AccessHelper.ExecuteNonQuery(Sql);
                return true;
            }
            catch{ return false;}
        }
        public static bool InsertProc(LopHocDTO lh)
        {
            try
            {
                Dictionary<string, object> para = new Dictionary<string, object>();
                para.Add("TenLop", lh.TenLop);
                para.Add("SiSo", lh.SiSo);
                para.Add("MaKhoi", lh.MaLop);
                Config.AccessHelper.ExecuteProcedure("ThemLopHoc", para);
                return true;
            }
            catch
            {
                return false;
            }
        }
        public static bool Update(LopHocDTO lh)
        {
            try
            {
                string sql = "UPDATE LOPHOC SET TenLop = '" + lh.TenLop + "',SiSo = " + lh.SiSo + ",MaKhoi = '" + lh.MaKhoi +  "'where MaLop=" + lh.MaLop;
                Config.AccessHelper.ExecuteNonQuery(sql);
                return true;
            }
            catch
            {
                return false;
            }
        }
        public static bool UpdateProc(LopHocDTO lh)
        {
            try
            {
                Dictionary<string, object> para = new Dictionary<string, object>();
                para.Add("MaLop", lh.MaLop);
                para.Add("TenLop", lh.TenLop);
                para.Add("SiSo", lh.SiSo);
                para.Add("MaKhoi", lh.MaKhoi);
                Config.AccessHelper.ExecuteProcedure("SuaLopHoc", para);
                return true;
            }
            catch
            {
                return false;
            }
        }
        public static bool Delete(LopHocDTO lh)
        {
            try
            {
                string sql = "DELETE FROM LOPHOC WHERE MaLop=" + lh.MaLop;
                Config.AccessHelper.ExecuteNonQuery(sql);
                return true;
            }
            catch
            {
                return false;
            }
        }
        public static bool DeleteProc(LopHocDTO lh)
        {
            try
            {
                Dictionary<string, object> para = new Dictionary<string, object>();
                para.Add("MaLop", lh.MaLop);
                Config.AccessHelper.ExecuteProcedure("XoaLopHoc", para);
                return true;
            }
            catch
            {
                return false;
            }
        }
    }
}
